<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>

<script>
description("Test unwrapping an RSA key with AES-CBC.");

jsTestIsAsync = true;

var extractable = true;
var nonExtractable = false;

var unwrappingKeyOctets = hexStringToUint8Array("2a00e0e776e94e4dc89bf947cebdebe1");
var wrappedKey = hexStringToUint8Array("b490dedb3abc3fd545e146538e6cc3ca"); // An empty encrypted JSON.

debug("Importing an unwrapping key...");
crypto.subtle.importKey("raw", unwrappingKeyOctets, {name: "AES-CBC"}, nonExtractable, ["unwrapKey"]).then(function(result) {
    unwrappingKey = result;
    shouldBe("unwrappingKey.algorithm.name", "'AES-CBC'");
    var unwrapAlgorithm = {name: "AES-CBC", iv: hexStringToUint8Array("000102030405060708090a0b0c0d0e0f")};
    debug("Unwrapping a key...");
    var importAlgorithm = {name: 'RSASSA-PKCS1-v1_5', hash: {name: 'sha-1'} };
    return crypto.subtle.unwrapKey("jwk", wrappedKey, unwrappingKey, unwrapAlgorithm, importAlgorithm, extractable, ["sign"]);
}).then(undefined, function(result) {
    logError(result);
    finishJSTest();
}).then(finishJSTest, failAndFinishJSTest);

</script>

</body>
</html>
